/*
 ============================================================================
 Name        : daemon.c
 Author      : Piotr Kowalski & Radek Morytko
 Version     :
 Copyright   : 
 Description : Deamon for memory monitoring.
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#include "daemon.h"
#include "common.h"
#include <logger.h>
#include "utils.h"
#include "monitor.h"
#include "dispatcher.h"

int main(void) {

	pid_t pid, sid;
	pthread_t dispatcher_thread;

	/*pid = fork();

	if(pid < 0)
	{
		LOG_MSG("Nie mozna wywolac fork.");
		exit(EXIT_FAILURE);
	}

	if(pid > 0)
	{
		LOG_MSG("Fork wywolany. Konczenie procesu.");
		exit(EXIT_SUCCESS);
	}

	sid = setsid();

	if( sid < 0)
	{
		LOG_MSG("Nie mozna utworzyc session id.");
		exit(EXIT_FAILURE);
	}*/

	if(pthread_create(&dispatcher_thread, NULL, start_dispatcher, NULL))
	{
		LOG_MSG("Cannot start a dispatcher thread");
	}

	pthread_join( dispatcher_thread, NULL );

	return EXIT_SUCCESS;
}
